package com.witdata.rabbit.config;

import com.witdata.rabbit.consumer.instance.InstanceConsumer;
import com.witdata.rabbit.producer.InstanceProducer;
import com.witdata.rabbit.service.InstanceMessageService;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.rabbit.connection.ConnectionFactory;
import org.springframework.amqp.rabbit.core.RabbitAdmin;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class InstanceConfiguration {

    @Bean
    public InstanceMessageService instanceMessageService(ConnectionFactory connectionFactory, InstanceConsumer instanceConsumer, RabbitAdmin rabbitAdmin, InstanceProducer instanceProducer) {
        InstanceMessageService instanceMessageService = new InstanceMessageService(connectionFactory, instanceConsumer, rabbitAdmin);
        instanceMessageService.addQueue("/" + instanceProducer.getServerId() + "/recv");
        return instanceMessageService;
    }

    @Bean
    public Queue recvQueue() {
        return new Queue("/server/recv");
    }
}
